﻿using B.S.Warehouse.Domain;
using B.S.Warehouse.ErrorCord;
using B.S.Warehouse.Read.Api.Application.Command.WarehouseManagementCommand;
using MediatR;
using SqlSugar;

namespace B.S.Warehouse.Read.Api.Application.Handelr.WarehouseManagementCommandHandler
{
    public class GetStorageAreaCommandHandler : IRequestHandler<GetStorageAreaCommand, ApiResult<List<StorageArea>>>
    {
        private readonly ISqlSugarClient db;

        public GetStorageAreaCommandHandler(ISqlSugarClient db)
        {
            this.db = db;
        }

        public async Task<ApiResult<List<StorageArea>>> Handle(GetStorageAreaCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<StorageArea>> result = new ApiResult<List<StorageArea>>();

            var list = await db.Queryable<StorageArea>().Where(p => p.WarehouseID == request.WarehouseID).ToListAsync();

            result.data = list;

            result.Code = ApiEnum.显示成功;
            result.MAG = "查询成功";

            return await Task.FromResult(result);
        }
    }
}
